import { Container} from "pixi.js";

import Mixin from './utils/Mixin.js';
import DrawBase from './DrawBase.js';
import Selector from './utils/selector.js';

/**
 * 组
 *
 * GroupItem
 * 
 * @extends PIXI.Container
 * @class
 * @memberof Nice.DrawBase
 * @author iwangcj
 */
class GroupItem extends Container {
    constructor() {
        super();
    }

    /**
	 * 获取风格属性
	 * @param {string} key 
	 */
	_getAttrStyle(key) {

        let result = undefined; //未定义
        if ('visible' === key) {
            result = this.visible;
        }

        return result;
    }

	/**
	 * 设置风格属性
	 * @param {string} key 
	 * @param {any} value
	 */
    _setAtterStyle(key, value=undefined) {
        let isOk = true;
        if ('visible' === key) {
            this.visible = value;
        }
        else {
            isOk = false;
        }
        return isOk;
    }


	/**
     * @param {*} key 
     * @param {*} value 
     */
    attrStyle(key, value=undefined) {
        if (undefined != value) {
            return this._setAtterStyle(key, value)
        }
        else {
            return this._getAttrStyle(key);
        }
    }

	/**
     * get/set 属性
     * @param {*} key 
     * @param {*} value 
     */
    attr(key, value) {
        if (undefined != value) {
			let isOk = this.attrBase(key, value);
			!isOk && (isOk = this.attrStyle(key, value));
			return isOk;
        }
        else {
			let result = this.attrBase(key);
			undefined == result && (result = this.attrStyle(key));
            return result;
        }
    }

    /**
     * 查找元素
     * @param {string} selector 
     */
    select(selector) {
        return Selector.select(this, selector);
    }

    /**
     * 查找所有图元
     */
    selectAll() {
        return Selector.select(this, "*");
    }

    // /**
    //  * 设置组件状态
    //  * @param {number} state 
    //  */
    // setComponentState(state) {
    //     const childrens = this.allChildren();
    //     childrens.forEach((item)=>{
    //         const compState = item.componentState;
    //         if (compState) {
    //             item.visible = compState == state;
    //         }
    //     });
    // }
}

export default Mixin(GroupItem, DrawBase);